/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package SessionBeans.actions;

import SessionBeans.entites.FileService;
import api.action.crates.Server.UpdateFileCrate;
import api.exception.TCloudAplicationException;
import entities.AccountHeader;
import entities.File;
import javax.ejb.EJB;
import javax.ejb.LocalBean;
import javax.ejb.Stateless;

/**
 *
 * @author Tomas
 */
@Stateless
@LocalBean
public class UpdateFileService implements InvokeActionInterface<UpdateFileCrate> {
    @EJB
    private FileService fileService;

    // Add business logic below. (Right-click in editor and choose
    // "Insert Code > Add Business Method")
    @Override
    public void processAction(UpdateFileCrate actionData, Long userId, AccountHeader accHeader) throws TCloudAplicationException {
        File find = Utils.findFile(accHeader.getRootFolder(), actionData.getPath());
        if(find == null){
            throw new TCloudAplicationException(102, actionData.getPath());
        }

        if (actionData.getName() != null) {
            fileService.updateFile(userId, find, actionData.getValue(), actionData.getName());            
        }else{
            fileService.updateFile(userId, find, actionData.getValue());
        }
    }
}
